#include "pch.h"
#include "RGB.h"

CRGB::CRGB(void)
{
	red = 1.0; green = 1.0; blue = 1.0; alpha = 0.0;
		
}
CRGB::~CRGB(void)
{
}
void CRGB::Normalize(void)
{
	red = (red < 0.0) ? 0.0 : ((red > 1.0) ? 1.0 : red);
	green = (green < 0.0) ? 0.0 : ((green > 1.0) ? 1.0 : green);
	blue = (blue < 0.0) ? 0.0 : ((blue > 1.0) ? 1.0 : blue);
}
CRGB::CRGB(double red, double green,double blue,double alpha)
{
	this->red = red; this->green = green; this->blue = blue; this->alpha = alpha;
}

CRGB operator+(const CRGB& c0, const CRGB& c1)
{
	CRGB color;
	color.red = c0.red + c1.red;
	color.green = c0.green + c1.green;
	color.blue = c0.blue + c1.blue;
	return color;
}

CRGB operator-(const CRGB& c0,const CRGB& c1)
{
	CRGB color;
	color.red = c0.red - c1.red;
	color.green = c0.green - c1.green;
	color.blue = c0.blue - c1.blue;
	return color;
}

CRGB operator*(const CRGB& c0,const CRGB& c1)
{
	CRGB color;
	color.red = c0.red * c1.red;
	color.green = c0.green * c1.green;
	color.blue = c0.blue * c1.blue;
	return color;
}

CRGB operator*(const CRGB& c,double scalar)
{
	CRGB color;
	color.red = scalar * c.red;
	color.green = scalar * c.green;
	color.blue = scalar * c.blue;
	return color;
}

CRGB operator*(double scalar, const CRGB& c)
{
	CRGB color;
	color.red = scalar * c.red;
	color.green = scalar * c.green;
	color.blue = scalar * c.blue;
	return color;
}

CRGB operator/(const CRGB& c,double scalar)
{
	if (fabs(scalar) < 1e-4)
		scalar = 1.0;
	CRGB color;
	color.red = c.red / scalar;
	color.green = c.green / scalar;
	color.blue = c.blue / scalar;
	return color;
}

CRGB operator+=(CRGB& clr0,CRGB& clr1)
{
	clr0.red += clr1.red;
	clr0.green += clr1.green;
	clr0.blue += clr1.blue;
	return clr0;
}

CRGB operator-=(CRGB& clr0,CRGB& clr1)
{
	clr0.red -= clr1.red;
	clr0.green -= clr1.green;
	clr0.blue -= clr1.blue;
	return clr0;
}

CRGB operator*=(CRGB& clr0,CRGB& clr1)
{
	clr0.red *= clr1.red;
	clr0.green *= clr1.green;
	clr0.blue *= clr1.blue;
	return clr0;
}

CRGB operator/=(CRGB& clr0,double scalar)
{
	if (fabs(scalar) < 1e-4)
		scalar = 1.0;
	clr0.red /= scalar;
	clr0.green /= scalar;
	clr0.blue /= scalar;
	return clr0;
}
